$(function() {
	$('input[type=checkbox').on('click', function() {
		checkall(this)
	});
	$('.delete-list').on('click', function() {
		popup(this, "{:url('delete')}");

	});
	//删除多个
	$(".delete-multiple").on('click',function(){
		popup(this,"{:url('delete')}");
	});
	$('.startusing').on('click', function() {
		popup(this, "{:url('state')}");
	});
	$('.forbidden').on('click', function() {
		popup(this, "{:url('state')}");
	});
	$('.choose').on('click', function() {
		var index = parent.layer.getFrameIndex(window.name);
		parent.$('.car_use').attr("value", $(this).data('name'));
		parent.$('.car_use_id').attr("value", $(this).data('id'));
		console.log(parent.$('.car_use').data('department'))
		if(parent.$('.car_use').data('department')){
			console.log('department')
			console.log($(this).data("id"))
		$.ajax({
			method: 'POST',
			url: "{:url('admin/used/department')}",
			data: {
				id: $(this).data('id')
			},
			success: function(res) {
				console.log(res)
				var department;
				for(var d in res) {
					department += `<option value="${res[d].department_id}">${res[d].name}</option>`
				}
				parent.$('.department').html(department)
				parent.layer.close(index);
			}

		})
		}else{
			parent.layer.close(index);
		}
		//		

	});
	$('.detail').on('click', function() {
		var car_use_id=$(this).closest('tr').data('id')
		console.log(car_use_id)
		var detail = layer.open({
			type: 1,
			title:$(this).closest('tr').find('td').eq(1).html(),
			skin: 'layui-layer-rim', //加上边框
			area: ['250px', '100px'], //宽高
			content: `
		  	<table style='width:100%;height:'100%;' data-caruseid="${car_use_id}">
		  		<tbody>
		  		<tr>
		  		<td style='text-align:center'>
					<div class="tpl-table-black-operation">
						<a class="department" style='margin-top:30px'>
							<i class="am-icon-pencil"></i>部门
						</a>
					</div>
				</td>
				<td data-id="{$item.car_rental_id}" style='text-align:center'>
					<div class="tpl-table-black-operation">
						<a class="passenger"  style='margin-top:30px'>
							<i class="am-icon-pencil"></i> 乘客
						</a>
					</div>
				</td>
				<td data-id="{$item.car_rental_id}" style='text-align:center'>
					<div class="tpl-table-black-operation">
						<a class="order" style='margin-top:30px'>
							<i class="am-icon-pencil"></i> 订单
						</a>
					</div>
				</td>
				<td data-id="{$item.car_rental_id}" style='text-align:center'>
					<div class="tpl-table-black-operation">
						<a class="" style='margin-top:30px'>
							<i class="am-icon-pencil"></i> 报表
						</a>
					</div>
				</td>
				</tr>
				</tbody>
		  	</table>
		  `
		});
		$('.department').on('click', function() {
			console.log("{:url('passenger/index',['op'=>'search'])}?car_use_id="+$(this).closest('table').data('caruseid'))
			layer.close(detail);
			department("{:url('department/index',['op'=>'search'])}?car_use_id="+$(this).closest('table').data('caruseid'))
		});
		$('.passenger').on('click', function() {
			
			layer.close(detail);
			
			department("{:url('passenger/index',['op'=>'search'])}?car_use_id="+$(this).closest('table').data('caruseid'))
		});
		$('.order').on('click', function() {
			layer.close(detail);
			department("{:url('order/index',['op'=>'search'])}?car_use_id="+$(this).closest('table').data('caruseid'))
		});
	});
	

})